<?php




namespace App\Http\Controllers\Api\Site;


use App\Http\Controllers\Api\BasicController;
use App\Models\SiteApp;
use App\Models\Site\SiteBanner;
use App\Models\SiteCity;
use App\Models\SiteConfig;
use App\Models\SocialFeedback;
use App\Services\Data;
use Jiannei\Response\Laravel\Support\Facades\Response;
use Tencent\TLSSigAPIv2;

class BannerController extends BasicController
{

    /**
     * @api {get} /site/data/banner 轮播图
     * @apiName SiteDataBanner
     * @apiGroup SiteData
     *
     * @apiParam {Number} [type=1] 类型 1=首页2=个人中心
     */
    public function banner()
    {
        $type = $this->request->input('type', 1);
        $cate_id_1 = $this->request->input('cate_id_1', 0);
//        dd($cate_id_1);
        $result = (new SiteBanner())->getList($type, $cate_id_1);
        if (!$result->toArray()) {
            $results = [
                'code' => 200,
                'message' => "success",
                'data' => [],
            ];
            return json_encode($results);
        }
        return Response::success($result);
    }

    /**
     * @api {get} /site/data/config 配置信息
     * @apiName SiteDatConfig
     * @apiGroup SiteData
     *
     * @apiParam {String} [key] 参数名
     */
    public function config()
    {
//        $result['skill']=explode(',',config('teacher.skill'));
//        $result['therapy']=explode(',',config('teacher.therapy'));
//        $result['listen']=explode(',',config('teacher.listen'));
        $result['base'] = config('base');
        $result['teacher'] = config('teacher');
        return Response::success($result);
    }

    /**
     * @api {get} /site/data/city  城市列表
     * @apiName SiteDataCity
     * @apiGroup Site
     * @apiDescription 城市列表
     *
     */
    public function city()
    {
        $fields = ['id', 'pid', 'first', 'short', 'lng', 'lat'];
        $city = SiteCity::where('level', 2)->select($fields)->get();
        $result = collect($city)->sortBy('first')->groupBy('first');
        return Response::success($result);
    }

    public function getCityTree(){
        $fields = ['id', 'pid', 'name'];
        $city=SiteCity::select($fields)->get()->toArray();
        $city=(new Data())->arrtotree($city,'id','pid','children');
        //dd($city);
        return Response::success($city);
    }

    /**
     * @api {get} /site/data/hot  热门城市
     * @apiName SiteDataHot
     * @apiGroup Site
     * @apiDescription 热门城市
     *
     */
    public function hot()
    {
        $fields = ['id', 'pid', 'first', 'short', 'lng', 'lat'];
        $city = SiteCity::where('hot', 1)->select($fields)->get();
        return Response::success($city);
    }

    public function version()
    {
        $port_type = $this->request->input('port_type');
        $code = $this->request->input('code', 100);
        $result = (new SiteApp())->getNew($port_type, $code);
        return Response::success($result);
    }

    public function feedback()
    {
        $fields = ['content', 'images', 'contact_name', 'contact_detail'];
        $data = $this->data($fields);
        $result = SocialFeedback::create($data);
        return Response::success($result);
    }


}
